﻿using System;
using System.Collections.Generic;
using System.Text;
using Core.Parser.ASN1Parser.Nodes;
using Core.Model;
using Core.Model.Data;
using Core.Exceptions;
using Core.Model.Data.Type;

namespace Core.Parser.ASN1Parser.Builders
{
    internal class IngredientBuilder
    {

        internal static void Build(TaggedNode node, Ingredient ingredient, Group group)
        {
            RootBuilder.Build(node, ingredient, group);

            if (ingredient.ObjectIdentifier.ObjectNumber == 0)
            {
                throw new Exception("Ingredient parsed with invalid object number 0");
                //log.warning( "Ingredient parsed with invalid object number 0" );
            }

            TaggedNode e;

            if ((e = node[ASN1ContextCodes.C_INITIALLY_ACTIVE]) != null)
                ingredient.InitiallyActive = e.First.BoolValue;

            if ((e = node[ASN1ContextCodes.C_CONTENT_HOOK]) != null)
                ingredient.ContentHook = e.First.IntValue;

            if ((e =  node[ASN1ContextCodes.C_ORIGINAL_CONTENT]) != null)
                ingredient.OriginalContent = ContentRefBuilder.BuildContent(e, group);

            if ((e =  node[ASN1ContextCodes.C_SHARED]) != null)
                ingredient.Shared = e.First.BoolValue;
        }

 

    }
}
